﻿using System.Collections.Generic;
using Library.OrmEnterpriseEntity.TableInfo;

namespace Library.OrmEnterpriseEntity {
	public sealed class SelectStatementWrapper : StatementWrapper {
		public SelectStatementWrapper(QueryStatement statement)
			: base(statement) {
		}
		public int SelectedColumnCount { get { return Statement.SelectCols.Count; } }


		public int Page { get; internal set; }
		public int PageSize { get; internal set; }

		public GlobalEntityView RootTable { get { return Statement.Root; } }

		public IEnumerable<JoinStatement> Joins {
			get {
				return Statement.Joints;
			}
		}

		public DbColumnView[] SelectedCols { get { return Statement.SelectCols.ToArray(); } }

		public OrderStatement[] Orders {
			get { return Statement.Orders.ToArray(); }
		}

		private ISelectOption _selectionOption;
		private bool _isCastedSelectOption;
		public ISelectOption SelectOption {
			get {
				if (!_isCastedSelectOption) {
					_isCastedSelectOption = true;
					var select = Statement as SelectQueryStatement;
					if (select != null) {
						_selectionOption = select.SelectOption;
					}
				}

				return _selectionOption;
			}
		}



		public int RowReturn { get; set; }
		public DbColumnView CountColumn {
			get { return Statement.CountCol; }
		}
		public DbColumnView[] GroupBy {
			get { return Statement.Groups; }
		}

		public DbColumnView[] Sum {
			get { return Statement.Sums; }
		}

		public bool CrossAll { get { return Statement.CrossAll; } }
		public IList<short> CrossList { get { return Statement.Crosses; } }
		public GlobalEntityView RootRowType { get { return Statement.RootRowType; } }

	}
}
